package simulation;

import streaming.StreamingConfig;

/**
 * Represents window of availability or interest - Has method to verify if 
 * seqNo is within window.
 * @author Maya Haridasan
 */
public class Window {
	
	int packetStartSeqNo;
	double windowSize;
	
	public Window(double newWindowSize) {
		this.setWindowSize(newWindowSize);
		this.setPacketStartSeqNo(-(int)(StreamingConfig.MCASTRATE * windowSize));
	}
	
	public boolean isWithin(int seqNo) {
		return (seqNo >= this.getPacketStartSeqNo());		
	}
	
	public void update(Integer id) {
//		System.out.println("[MSG08] Atualizando startSeqNo do no " + id + " para " + (this.getPacketStartSeqNo() + StreamingConfig.MCASTRATE));
		this.setPacketStartSeqNo(this.getPacketStartSeqNo() + StreamingConfig.MCASTRATE);
	}
	
	public int calculateOffset(int seqNo) {
		return (seqNo - this.getPacketStartSeqNo());
	}

	/* Getters and Setters */
	
	public int getPacketStartSeqNo() {
		return packetStartSeqNo;
	}

	public void setPacketStartSeqNo(int packetStartSeqNo) {
		this.packetStartSeqNo = packetStartSeqNo;
	}

	public double getWindowSize() {
		return windowSize;
	}

	public void setWindowSize(double windowSize) {
		this.windowSize = windowSize;
	}
}
